package cn.stylefeng.guns.modular.controller;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.auth.model.LoginUser;
import cn.stylefeng.guns.modular.dto.FuzzySearchSframeDto;
import cn.stylefeng.guns.modular.entity.ScheduleForm;
import cn.stylefeng.guns.modular.entity.ScheduleFrame;
import cn.stylefeng.guns.modular.service.ScheduleFormService;
import cn.stylefeng.guns.modular.service.ScheduleFrameItemService;
import cn.stylefeng.guns.modular.service.ScheduleFrameService;
import cn.stylefeng.guns.modular.utils.UserMessage;
import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("testform")
public class TestController extends BaseController {
    @Autowired
    private ScheduleFrameItemService scheduleFrameItemService;
    @Autowired
    private ScheduleFrameService scheduleFrameService;
    @Autowired
    private ScheduleFormService scheduleFormService;


    /**
     * 显示选择框架后所有的框架项个数
     * @return
     */
    @RequestMapping("showFrameItem")
    public String showFrameItem(Model model){
        /**
         * 得到当前登陆者的信息
         */
        long userId= UserMessage.getUserId();
        //假设选择的sframeId为2

        int sframeId=1;
      int countNum =  scheduleFrameItemService.selectSframeItemCountBySframeId(sframeId);

      //显示所有框架（包括框架项）
        List<ScheduleFrame> scheduleFrames=scheduleFrameService.selectAllScheduleFrame(userId);





        model.addAttribute("scheduleFrames",scheduleFrames);
      model.addAttribute("userId",userId);

        FuzzySearchSframeDto fuzzySearchSframeDto =new FuzzySearchSframeDto();

        fuzzySearchSframeDto.setPublish("true");
        fuzzySearchSframeDto.setFrameDraft("false");

       /* List<ScheduleFrame> list= scheduleFrameService.fuzzySearchSframe(fuzzySearchSframeDto);*/

        List<ScheduleForm> scheduleForms=scheduleFormService.selectById(userId);
        ScheduleForm scheduleForm=scheduleFormService.selectSformBySformId(3);

        //假设选中的为框架为1
       ScheduleFrame scheduleFrame = scheduleFrameService.selectScheduleFrameById(1);
        model.addAttribute("scheduleFrame",scheduleFrame);
        model.addAttribute("scheduleForm",scheduleForm);
        model.addAttribute("scheduleForms",scheduleForms);
   /*     model.addAttribute("list",list);*/

        return "/testForm.html";

    }
}
